package xby.study.annotations.util;

import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.test.context.ContextConfiguration;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class TestPlus {

    public static final String A = "a";
    public static final String B = "b";


    public static void main(String[] args) {

        /*
         * get 支持当前， 和 向上查一层
         * */

        Ant a = AnnotationUtils.getAnnotation(T.class, Ant.class);
        System.out.println(a);

        Bnt b = AnnotationUtils.getAnnotation(T.class, Bnt.class);
        System.out.println(b);

        /*
         * find 支持无限递归向上查元注解
         * */
        Cnt c = AnnotationUtils.findAnnotation(T.class, Cnt.class);
        System.out.println(c);


//        System.out.println("测试三个互为别名的属性>>>");
//
//        MyTestConfig m = AnnotationUtils.getAnnotation(T.class, MyTestConfig.class);
//        System.out.println(m);


    }
}


@Ant(name = "CNM")
@MyTestConfig(name1 = {TestPlus.A, TestPlus.B})
class T {

}

@Retention(RetentionPolicy.RUNTIME)
@Bnt
@interface Ant {


    @AliasFor(annotation = Cnt.class, attribute = "bigName")
    String name() default "TTT";

    @AliasFor(annotation = Cnt.class, attribute = "bigAge")
    String age() default "TTT";

}

@Cnt
@Retention(RetentionPolicy.RUNTIME)
@interface Bnt {

}


@Retention(RetentionPolicy.RUNTIME)
@interface Cnt {

    @AliasFor(attribute = "bigAge")
    String bigName() default "HAHA";

    @AliasFor(attribute = "bigName")
    String bigAge() default "HAHA";

}


@ContextConfiguration
@Retention(RetentionPolicy.RUNTIME)
@interface MyTestConfig {

    @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
    String[] name1() default {};

    @AliasFor(annotation = ContextConfiguration.class, attribute = "value")
    String[] name2() default {};

    @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
    String[] name3() default {};
}